package com.lcz.mobilesafe.utils;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import com.lcz.mobilesafe.activity.BaseApplication;

/**
 * Created by hp on 2017/1/18.
 */

public class AppInfoUtils {
    private static PackageManager packageManager = BaseApplication.getApplication().getPackageManager();
    /**
     * 获取版本号名称
     * @return  版本号名称
     */
    public static String getVersionName() {

        try {
            //获取包信息
            PackageInfo packageInfo = packageManager.getPackageInfo(BaseApplication.getApplication().getPackageName(), 0);
            //返回版本号
            return packageInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 获取版本号
     * @return  版本号
     */
    public static int getVersionCode(){
        try {
            return packageManager.getPackageInfo(BaseApplication.getApplication().getPackageName(),0).versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return -1;
    }
}
